﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CRM.Database.Model.Customers>" %>
<%@ Import Namespace="System.Threading" %>
<%@ Import Namespace="CRM.Models" %>
<%@ Import Namespace="CRM.Resourses" %>

<% Html.DevExpress().GridView(settings =>
                    {
                        settings.Name = "gdTools";
                        settings.KeyFieldName = "IdCustomersTool";
                        settings.CallbackRouteValues =
                                           new { Controller = "Customers", Action = "CustomerEquipmentsTools", customerId = Model.IdCustomer };
                        settings.SettingsPager.PageSize = 20;

                        settings.Settings.ShowGroupPanel = true;
                        settings.Settings.ShowFilterRow = true;
                        
                      
                        settings.Columns.Add(column =>
                        {
                            column.FieldName = "Tools.IdToolGroup";
                            column.Caption = Resourses.ToolGroup;
                            column.ColumnType = MVCxGridViewColumnType.ComboBox;

                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                            if (comboBoxProperties != null)
                            {
                                comboBoxProperties.DataSource =
                                    DB.GetLocalizedToolGroupsNames(
                                                         Thread.CurrentThread.CurrentCulture.ToString());

                                comboBoxProperties.TextField = "LocaLizedString";
                                comboBoxProperties.ValueField = "Id";
                                comboBoxProperties.ValueType = typeof(int);
                            }
                        });
                        
                      settings.Columns.Add(column =>
                        {
                            column.FieldName = "Tools.IdVendor";
                            column.Caption = Resourses.ToolsVendor;
                            column.ColumnType = MVCxGridViewColumnType.ComboBox;

                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                            if (comboBoxProperties != null)
                            {
                                comboBoxProperties.DataSource =
                                    DB.GetLocalizedToolsVendors(
                                                         Thread.CurrentThread.CurrentCulture.ToString());

                                comboBoxProperties.TextField = "LocaLizedString";
                                comboBoxProperties.ValueField = "Id";
                                comboBoxProperties.ValueType = typeof(int);
                            }
                        });
                        
                        settings.Columns.Add(column =>
                        {
                            column.Caption = Resourses.ToolsMark;
                            column.FieldName = "IdTool";
                        });
                        settings.Columns.Add(column =>
                        {
                            column.Caption = Resourses.ToolsCount;
                               column.FieldName = "ToolCount";
                        });
                        settings.Columns.Add(column =>
                        {
                            column.Caption = Resourses.ToolsFreeOfCharge;
                               column.FieldName = "ToolCount4Free";
                        });
                        settings.Columns.Add(column =>
                        {
                            column.Caption = Resourses.ToolsSold;
                            column.FieldName = "ToolSold";
                        });
                    }

    ).Bind(Model.CustomersTools).GetHtml();              %>